<?php

namespace App\Service\CallingCards;

use App\Jobs\CallingCards\AutoCloseUsersStoriesLog;
use App\Library\FeiShu\SendFs;
use App\Models\Common\ConfigModel;
use App\Models\FeishuCallingCard\FeishuCallingCardUser;
use App\Models\FeishuCallingCard\FeishuCallingCardUsersStoriesLog;
use App\Remote\Rms\RmsUserRemote;
use App\Service\OpenShop\FeishuMini\ProgrammingService;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Kuafu\GeneralFs\BuildFs;
use Kuafu\GeneralFs\CardStyle\FsCardGrid;
use Kuafu\GeneralFs\FsCardEstablish;

class UsersStoriesLogService
{
    const TYPE_USER    = 1;// 按用户
    const TYPE_ARTICLE = 2;// 按文章

    /**
     * 文章阅读事件
     * @param FeishuCallingCardUser|null $user
     * @param array $data
     * @param int $source
     * @param string $unionid
     * @return array
     */
    public static function article(FeishuCallingCardUser $user = null, array $data, int $source, string $unionid): array
    {
        $userId = 0;
        if ($source == FeishuCallingCardUsersStoriesLog::SOURCE_WECHAT_APPLET && $user) {
            $userId = $user->id;
        } else {
            $userId = $unionid;
        }
        $info = FeishuCallingCardUsersStoriesLog::getInfo($data['storiesId'], $userId);
        $time = time();
        Log::info(
            'UsersStoriesLog:', [
                'data'    => $data,
                'info'    => $info,
                'userId'  => $userId,
                'source'  => $source,
                'unionid' => $unionid,
            ]
        );
        switch ($data['type']) {
            case FeishuCallingCardUsersStoriesLog::TYPE_OPEN_ARTICLE:// 进入文章
            case FeishuCallingCardUsersStoriesLog::TYPE_HEARTBEAT:// 心跳更新数据
                if (!$info) {
                    FeishuCallingCardUsersStoriesLog::createData(
                        [
                            'storiesId'    => $data['storiesId'],
                            'usersId'      => $userId,
                            'openTime'     => $time,
                            'duration'     => 1,// 阅读时长
                            'type'         => $data['type'],
                            'createdAt'    => $time,
                            'createdByUid' => $userId,
                            'updatedAt'    => $time,
                            'updatedByUid' => $userId,
                            'source'       => $source,
                        ]
                    );

                    // 生成延迟队列 延迟队列过期时间：3分钟 （3分钟之内同一个人同一篇文章阅读算一次）
                    $autoScriptDelayTime = self::getUsersStoriesConfig()['autoScriptDelayTime'] ?? 0;

                    dispatch((new AutoCloseUsersStoriesLog($data['storiesId'], $userId, $source))->onQueue(AutoCloseUsersStoriesLog::QUEUE_NAME))
                        ->delay($autoScriptDelayTime + 1);
                } else {
                    if ($data['type'] == FeishuCallingCardUsersStoriesLog::TYPE_HEARTBEAT) {
                        self::articleOperate($info, $time, $data);
                    } else {
                        FeishuCallingCardUsersStoriesLog::updateData($info->id, ['updatedAt' => $time]);
                    }
                }
                break;
            case FeishuCallingCardUsersStoriesLog::TYPE_EXIT_ARTICLE:// 离开事件
                if ($info) {
                    self::articleOperate($info, $time, $data);
                }
                break;
        }
        return [];
    }

    /**
     * 文章阅读操作
     * @param FeishuCallingCardUsersStoriesLog $info
     * @param int $time
     * @param array $data
     */
    public static function articleOperate(FeishuCallingCardUsersStoriesLog $info, int $time, array $data)
    {
        $openTime = $info->openTime;
        $duration = $time - $openTime;
        $update   = [
            'duration'  => $duration,// 阅读时长
            'updatedAt' => $time,
            'type'      => $data['type'],
        ];

        // 前端无法监控到篇幅，读完文章改成：阅读时间＞90S
        if ($data['isReadCompleted']) {// 前端现在能检测到阅读进度了
            $update['isReadCompleted'] = 1;
        } else {
            $readCompleteTime = self::getUsersStoriesConfig()['readCompleteTime'] ?? 0;
            if ($duration > $readCompleteTime) {
                $update['isReadCompleted'] = 1;
            }
        }
        if ($data['isClickJoin']) {// 是否点击加盟
            $update['isClickJoin'] = $data['isClickJoin'];
        }
        if ($data['type'] == FeishuCallingCardUsersStoriesLog::TYPE_EXIT_ARTICLE) {
            $update['exitTime'] = $time;// 离开时间
        }
        FeishuCallingCardUsersStoriesLog::updateData($info->id, $update);

        // 发送飞书通知
        if ($data['type'] == FeishuCallingCardUsersStoriesLog::TYPE_EXIT_ARTICLE) {
            self::sendFsNotice($info->id);
        }
    }

    /**
     * 微信加盟小程序用户阅读文章次数（大于此数字显示授权按钮）
     * @param int $usersId
     * @return bool
     */
    public static function isShowAuthButton(int $usersId): bool
    {
        $readCount = FeishuCallingCardUsersStoriesLog::query()
            ->where('usersId', $usersId)
            ->groupBy('storiesId')
            ->get()
            ->count();

        $limit = self::getUsersStoriesConfig()['readLimit'] ?? 0;//微信加盟小程序用户阅读文章次数（大于此数字显示授权按钮）
        return $readCount >= $limit;
    }

    /**
     * 获取微信加盟小程序阅读文章相关配置
     * readLimit:10,//微信加盟小程序用户阅读文章次数（大于此数字显示授权按钮）
     * readCompleteTime:90,//前端无法监控到篇幅，读完文章改成：阅读时间＞90S
     * autoScriptDelayTime:180,//文章阅读延迟队列自动关闭时间 3分钟
     * @return array
     */
    public static function getUsersStoriesConfig(): array
    {
        return Cache::remember(
            'wechatApplet:getUsersStoriesConfig', getSwitchCacheTime(600), function () {
            $data = ConfigModel::query()
                ->where('module', 'wechatApplet')
                ->where('name', 'usersStoriesConfig')
                ->value('value');
            return $data ? json_decode($data, true) : [];
        }
        );
    }

    /**
     * 文章数据看板
     * @param int $startTime
     * @param int $endTime
     * @param int $type
     * @param int $pageNum
     * @param int $pageSize
     * @return array
     */
    public static function getList(int $startTime, int $endTime, int $type, int $pageNum, int $pageSize): array
    {
        $group = 'usersId';// 用户ID 加盟商名片微信小程序用户表id
        if ($type == self::TYPE_ARTICLE) {
            $group = 'storiesId';// 文章ID 加盟商故事文章表id
        }

        $paginate = FeishuCallingCardUsersStoriesLog::query()
            ->with(['articleRel'])
            ->whereBetween('openTime', [$startTime, $endTime])
            ->groupBy($group)
            ->orderByDesc('openTime')
            ->orderByDesc('id')
            ->paginate($pageSize, ['*'], 'pageNum', $pageNum);

        if ($type == self::TYPE_ARTICLE) {// 按文章
            $storiesIds = array_column($paginate->items(), 'storiesId');

            // 文章pv
            $pvData = FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('storiesId', $storiesIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->groupBy('storiesId')
                ->selectRaw('count(1) total,storiesId')
                ->get()->keyBy('storiesId')->toArray();

            // 文章uv
            $uvData = [];
            FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('storiesId', $storiesIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->groupBy('usersId')
                ->groupBy('storiesId')
                ->selectRaw('count(1) total,storiesId,usersId')
                ->get()->map(
                    function ($item) use (&$uvData) {
                        if (isset($uvData[$item->storiesId])) {
                            $uvData[$item->storiesId] += 1;
                        } else {
                            $uvData[$item->storiesId] = 1;
                        }
                    }
                );

            // 读完人数
            $readCompleteData = [];
            FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('storiesId', $storiesIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->where('isReadCompleted', FeishuCallingCardUsersStoriesLog::READ_COMPLETE)
                ->groupBy('usersId')
                ->groupBy('storiesId')
                ->selectRaw('count(1) total,storiesId,usersId')
                ->get()->map(
                    function ($item) use (&$readCompleteData) {
                        if (isset($readCompleteData[$item->storiesId])) {
                            $readCompleteData[$item->storiesId] += 1;
                        } else {
                            $readCompleteData[$item->storiesId] = 1;
                        }
                    }
                );

            // 点击加盟人数
            $clickJoinData = [];
            FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('storiesId', $storiesIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->where('isClickJoin', FeishuCallingCardUsersStoriesLog::CLICK_JOIN)
                ->groupBy('usersId')
                ->groupBy('storiesId')
                ->selectRaw('count(1) total,storiesId,usersId')
                ->get()->map(
                    function ($item) use (&$clickJoinData) {
                        if (isset($clickJoinData[$item->storiesId])) {
                            $clickJoinData[$item->storiesId] += 1;
                        } else {
                            $clickJoinData[$item->storiesId] = 1;
                        }
                    }
                );

            $list = $paginate->map(
                function ($usersStoriesLog) use ($pageSize, $pageNum, $endTime, $startTime, $pvData, $uvData, $readCompleteData, $clickJoinData) {
                    return [
                        'storiesId'       => $usersStoriesLog->storiesId,                         // 文章id
                        'title'           => $usersStoriesLog->articleRel->name ?? '',           // 文章标题
                        'pv'              => $pvData[$usersStoriesLog->storiesId]['total'] ?? 0,  // 文章pv
                        'uv'              => $uvData[$usersStoriesLog->storiesId] ?? 0,           // 文章uv
                        'readCompleteNum' => $readCompleteData[$usersStoriesLog->storiesId] ?? 0, // 读完人数
                        'clickJoinNum'    => $clickJoinData[$usersStoriesLog->storiesId] ?? 0,    // 点击加盟人数
                    ];
                }
            );
        } else {// 按用户
            $usersIds = array_column($paginate->items(), 'usersId');

            // 阅读文章数/读完数
            $readData = $readCompleteData = [];
            FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('usersId', $usersIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->groupBy('storiesId')
                ->groupBy('usersId')
                ->selectRaw('count(1) total,usersId,storiesId')
                ->get()->map(
                    function ($item) use (&$readData) {
                        if (isset($readData[$item->usersId])) {
                            $readData[$item->usersId] += 1;
                        } else {
                            $readData[$item->usersId] = 1;
                        }
                    }
                );

            FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('usersId', $usersIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->where('isReadCompleted', FeishuCallingCardUsersStoriesLog::READ_COMPLETE)
                ->groupBy('storiesId')
                ->groupBy('usersId')
                ->selectRaw('count(1) total,usersId,storiesId')
                ->get()->map(
                    function ($item) use (&$readCompleteData) {
                        if (isset($readCompleteData[$item->usersId])) {
                            $readCompleteData[$item->usersId] += 1;
                        } else {
                            $readCompleteData[$item->usersId] = 1;
                        }
                    }
                );

            // 阅读时长
            $readDurationData = FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('usersId', $usersIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->groupBy('usersId')
                ->selectRaw('sum(duration) total,usersId')
                ->get()->keyBy('usersId')->toArray();

            // 是否点击加盟
            $clickJoinData = FeishuCallingCardUsersStoriesLog::query()
                ->whereIn('usersId', $usersIds)
                ->whereBetween('openTime', [$startTime, $endTime])
                ->where('isClickJoin', FeishuCallingCardUsersStoriesLog::CLICK_JOIN)
                ->groupBy('usersId')
                ->selectRaw('isClickJoin,usersId')
                ->get()->keyBy('usersId')->toArray();

            // 查询rms对应微信服务号的昵称和头像
            $customerPlatformUsers = collect(RmsUserRemote::getCustomerPlatformUsers($usersIds) ?? [])->keyBy('unionid')->toArray();

            $list = $paginate->map(
                function ($usersStoriesLog) use ($readData, $readCompleteData, $readDurationData, $clickJoinData, $customerPlatformUsers) {

                    // 用户最近阅读文章数据
                    $lastData = FeishuCallingCardUsersStoriesLog::query()
                        ->with(['articleRel'])
                        ->where('usersId', $usersStoriesLog->usersId)
                        ->orderByDesc('id')
                        ->first();

                    // 是否点击加盟
                    $isClickJoin = $clickJoinData[$usersStoriesLog->usersId]['isClickJoin'] ?? 0;

                    // 阅读时长
                    $durationText = self::getDurationText($readDurationData[$usersStoriesLog->usersId]['total'] ?? 0);
                    return [
                        'storiesId'         => $usersStoriesLog->storiesId,                                          // 用户首次阅读文章id
                        'usersId'           => $usersStoriesLog->usersId,                                            // 加盟商名片微信小程序用户表id
                        'openid'            => $customerPlatformUsers[$usersStoriesLog->usersId]['openId'] ?? '',    // 微信用户 openid
                        'nickName'          => $customerPlatformUsers[$usersStoriesLog->usersId]['name'] ?? '',      // 微信用户 nickName
                        'mobile'            => '',                                                                   // 微信用户 mobile
                        'headImage'         => $customerPlatformUsers[$usersStoriesLog->usersId]['headImage'] ?? '', // 微信用户 headImage
                        'firstReadTime'     => formatDate($usersStoriesLog->openTime ?? 0, ''),          // 用户首次阅读文章时间
                        'firstArticleTitle' => $usersStoriesLog->articleRel->name ?? '',                            // 用户首次阅读文章标题
                        'lastReadTime'      => formatDate($lastData->openTime ?? 0, ''),                 // 用户最近阅读文章时间
                        'lastArticleTitle'  => $lastData->articleRel->name ?? '',                                   // 用户最近阅读文章标题
                        'readCount'         => $readData[$usersStoriesLog->usersId] ?? 0,                            // 阅读文章数
                        'readCompleteCount' => $readCompleteData[$usersStoriesLog->usersId] ?? 0,                    // 读完数
                        'duration'          => $durationText,                                                        // 阅读时长
                        'isClickJoin'       => $isClickJoin ? '是' : '否',                                            // 是否点击加盟
                    ];
                }
            );
        }

        // 数据总搅:受到时间筛选器影响
        $totalData = self::getTotalData($startTime, $endTime);

        return [
            'list'      => $list,
            'count'     => $paginate->total(),
            'pageNum'   => $pageNum,
            'pageSize'  => $pageSize,
            'totalData' => $totalData,
        ];
    }

    /**
     * 数据总搅
     * @param int $startTime
     * @param int $endTime
     * @return array
     */
    public static function getTotalData(int $startTime, int $endTime): array
    {

        $pv = FeishuCallingCardUsersStoriesLog::query()
            ->whereBetween('openTime', [$startTime, $endTime])
            ->count();

        $uv = FeishuCallingCardUsersStoriesLog::query()
            ->whereBetween('openTime', [$startTime, $endTime])
            ->groupBy('usersId')
            ->get()
            ->count();

        // 点击加盟人数
        $clickJoinCount = FeishuCallingCardUsersStoriesLog::query()
            ->whereBetween('openTime', [$startTime, $endTime])
            ->where('isClickJoin', FeishuCallingCardUsersStoriesLog::CLICK_JOIN)
            ->groupBy('usersId')
            ->get()
            ->count();

        // 读完文章人次
        $readCompleteCount = FeishuCallingCardUsersStoriesLog::query()
            ->whereBetween('openTime', [$startTime, $endTime])
            ->where('isReadCompleted', FeishuCallingCardUsersStoriesLog::READ_COMPLETE)
            ->count();

        // 读完文章人数
        $readCompleteNum = FeishuCallingCardUsersStoriesLog::query()
            ->whereBetween('openTime', [$startTime, $endTime])
            ->where('isReadCompleted', FeishuCallingCardUsersStoriesLog::READ_COMPLETE)
            ->groupBy('usersId')
            ->get()
            ->count();

        return [
            'pv'                => $pv,
            'uv'                => $uv,
            'clickJoinCount'    => $clickJoinCount,   // 点击加盟人数
            'readCompleteCount' => $readCompleteCount,// 读完文章人次
            'readCompleteNum'   => $readCompleteNum,  // 读完文章人数
        ];
    }


    /**
     * 微信加盟小程序-文章数据看板
     * @param int $storiesId
     * @param int $startTime
     * @param int $endTime
     * @param int $pageNum
     * @param int $pageSize
     * @return array
     */
    public static function getReadArticleUses(int $storiesId, int $startTime, int $endTime, int $pageNum, int $pageSize): array
    {
        $paginate = FeishuCallingCardUsersStoriesLog::query()
            ->where('storiesId', $storiesId)
            ->whereBetween('openTime', [$startTime, $endTime])
            ->groupBy('usersId')
            ->orderByDesc('openTime')
            ->paginate($pageSize, ['*'], 'pageNum', $pageNum);

        $usersIds = array_column($paginate->items(), 'usersId');

        // 查询rms对应微信服务号的昵称和头像
        $customerPlatformUsers = collect(RmsUserRemote::getCustomerPlatformUsers($usersIds) ?? [])->keyBy('unionid')->toArray();

        // 是否读完
        $readCompleteData = FeishuCallingCardUsersStoriesLog::query()
            ->whereIn('usersId', $usersIds)
            ->where('storiesId', $storiesId)
            ->whereBetween('openTime', [$startTime, $endTime])
            ->where('isReadCompleted', FeishuCallingCardUsersStoriesLog::READ_COMPLETE)
            ->groupBy('usersId')
            ->selectRaw('isReadCompleted,usersId')
            ->get()->keyBy('usersId')->toArray();

        // 阅读时长
        $durationData = FeishuCallingCardUsersStoriesLog::query()
            ->whereIn('usersId', $usersIds)
            ->where('storiesId', $storiesId)
            ->whereBetween('openTime', [$startTime, $endTime])
            ->groupBy('usersId')
            ->selectRaw('sum(duration) total,usersId')
            ->get()->keyBy('usersId')->toArray();

        $list = $paginate->map(
            function ($usersStoriesLog) use ($readCompleteData, $durationData, $customerPlatformUsers) {

                // 阅读时长
                $durationText = self::getDurationText($durationData[$usersStoriesLog->usersId]['total'] ?? 0);
                return [
                    'usersId'   => $usersStoriesLog->usersId,                                            // 加盟商名片微信小程序用户表id
                    'openid'    => $customerPlatformUsers[$usersStoriesLog->usersId]['openId'] ?? '',    // 微信用户 openid
                    'mobile'    => '',                                                                   // 微信用户 mobile
                    'nickName'  => $customerPlatformUsers[$usersStoriesLog->usersId]['name'] ?? '',      // 微信用户 nickName
                    'headImage' => $customerPlatformUsers[$usersStoriesLog->usersId]['headImage'] ?? '', // 微信用户 headImage
                    'isRead'    => (bool)($readCompleteData[$usersStoriesLog->usersId] ?? 0),            // 是否读完
                    'duration'  => $durationText,                                                        // 阅读时长
                ];
            }
        );
        return [
            'list'     => $list,
            'count'    => $paginate->total(),
            'pageNum'  => $pageNum,
            'pageSize' => $pageSize,
        ];
    }

    /**
     * 用户离开时，将事件发送到飞书群
     * @param int $id
     */
    public static function sendFsNotice(int $id)
    {
        $getInfo = FeishuCallingCardUsersStoriesLog::query()
            ->with(['articleRel'])
            ->find($id);
        if ($getInfo) {
            $isReadText      = $getInfo->isReadCompleted == FeishuCallingCardUsersStoriesLog::READ_COMPLETE ? '是' : '否';// 是否读完
            $isClickJoinText = $getInfo->isClickJoin == FeishuCallingCardUsersStoriesLog::CLICK_JOIN ? '是' : '否';       // 是否点击了【我要加盟】

            $readCount = FeishuCallingCardUsersStoriesLog::query()
                ->where('usersId', $getInfo->usersId)
                ->groupBy('storiesId')->get()->count();// 历史阅读文章数（去重）

            $readCompleteCount = FeishuCallingCardUsersStoriesLog::query()
                ->where('usersId', $getInfo->usersId)
                ->where('isReadCompleted', FeishuCallingCardUsersStoriesLog::READ_COMPLETE)
                ->groupBy('storiesId')->get()->count();// 历史读完篇数（去重）

            $data = FeishuCallingCardUsersStoriesLog::query()
                ->where('usersId', $getInfo->usersId)
                ->selectRaw('min(openTime) firstTime,sum(duration) durationTotal')
                ->first();

            // 阅读时长
            $durationText = self::getDurationText($getInfo->duration);

            // 历史阅读时长
            $durationTotalText = self::getDurationText($data['durationTotal']);

            // 查询rms对应微信服务号的昵称和头像
            $customerPlatformUsers = collect(RmsUserRemote::getCustomerPlatformUsers([$getInfo->usersId]) ?? [])->keyBy('unionid')->toArray();

            $headImage    = $customerPlatformUsers[$getInfo->usersId]['headImage'] ?? '';
            $getFeishuImg = ProgrammingService::getFeishuImageKey($headImage);// 飞书照片

            $elements = (new FsCardGrid())
                ->pushTd('**【本次事件信息】** ', false)
                ->pushTd('')
                ->pushTd('**文章名称：** ' . $getInfo->articleRel->name ?? '-', false)
                ->pushTd('**进入时间：** ' . formatDate($getInfo->openTime), false)
                ->pushTd('**离开时间：** ' . formatDate($getInfo->exitTime), false)
                ->pushTd('**阅读时长：** ' . $durationText, false)
                ->pushTd('**是否读完：** ' . $isReadText, false)
                ->pushTd('')
                ->pushTd('**【用户基本信息】** ', false)
                ->pushTd('')
                ->pushTd('**用户ID：** ' . ($customerPlatformUsers[$getInfo->usersId]['openId'] ?? '-'), false)
                ->pushTd('**用户手机号：** ' . '-', false)
                ->pushTd('**用户昵称：** ' . ($customerPlatformUsers[$getInfo->usersId]['name'] ?? '-'), false)
                ->getElement();

            $card = (new FsCardEstablish())
                ->setHeader('blue', '微信加盟小程序文章阅读事件通知')
                ->pushElements($elements);

            $card = $card->pushElements(
                [
                    'tag'              => 'column_set',
                    'flex_mode'        => 'none',
                    'background_style' => 'default',
                    'columns'          => [
                        [
                            'tag'            => 'column',
                            'width'          => 'weighted',
                            'vertical_align' => 'top',
                            'elements'       => [
                                [
                                    'tag'        => 'markdown',
                                    'content'    => '**用户头像：** ',
                                    'text_align' => 'left'
                                ],
                                [
                                    'tag'        => 'img',
                                    'img_key'    => "{$getFeishuImg}",
                                    'preview'    => true,
                                    'scale_type' => 'crop_center',
                                    'size'       => 'medium',
                                    'alt'        => [
                                        'tag'     => 'plain_text',
                                        'content' => ''
                                    ]
                                ],
                            ],
                            'weight'         => 1
                        ],
                    ]
                ]
            );

            $elementsEnd = (new FsCardGrid())
                ->pushTd('**【历史行为信息】** ', false)
                ->pushTd('')
                ->pushTd('**历史阅读时长：** ' . $durationTotalText, false)
                ->pushTd('**历史阅读文章数（去重）：** ' . $readCount, false)
                ->pushTd('**历史读完篇数（去重）：** ' . $readCompleteCount, false)
                ->pushTd('**首篇文章阅读时间：** ' . formatDate($data['firstTime']), false)
                ->getElement();

            $card = $card->pushElements($elementsEnd);

            //            $card = (new FsCardEstablish())
//                ->setHeader('blue', '微信加盟小程序文章阅读事件通知')
//                ->pushElements($elements)
//                ->getTemplateArr();

            BuildFs::newRobot(SendFs::ROBOT_WX_APPLET_ARTICLE_READ_EVENT, BuildFs::MSG_TYPE_CARD)
                ->setCardContent($card->getTemplateArr())
                ->send();
        }
    }

    /**
     * 秒数转 xx分xx秒
     * @param int $seconds
     * @return string
     */
    public static function getDurationText(int $seconds): string
    {
        $minutes = floor($seconds / 60);
        $seconds = ($seconds % 60);

        return "{$minutes}分{$seconds}秒";
    }

}
